
#import "TimeInfo.h"
#import "HumanTimeInfo.h"

static NSDateFormatter   *_dateFormatter;

@implementation TimeInfo

+ (void)initialize {
    if (self == [TimeInfo class]) {
        NSTimeZone* localzone = [NSTimeZone localTimeZone];
        _dateFormatter = [[NSDateFormatter alloc] init];
        [_dateFormatter setTimeZone:localzone];
//        自定义区域语言  --  英文
        //[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
        _dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
        _dateFormatter.dateFormat = @"yyyy:MM:dd:MMM:MMMM:HH:mm:ss:aa:EEE:EEEE:SSS"; // SSSS
        // HH --> hh则为12小时制
    }
}

+ (HumanTimeInfo *)humanCanUnderstandFromDate:(NSDate *)date {
    if (date != nil) {
        NSArray *timeInfoArray = [[_dateFormatter stringFromDate:date] componentsSeparatedByString:@":"];
        HumanTimeInfo *info    = [HumanTimeInfo new];
        info.year              = timeInfoArray[0];
        info.mounth            = timeInfoArray[1];
        info.day               = timeInfoArray[2];
        info.enMounth          = timeInfoArray[3];
        info.fullEnMounth      = timeInfoArray[4];
        info.hour              = timeInfoArray[5];
        info.min               = timeInfoArray[6];
        info.sec               = timeInfoArray[7];
        info.amPm              = timeInfoArray[8];
        info.enWeakday         = timeInfoArray[9];
        info.fullWeakday       = timeInfoArray[10];
        info.mSec              = timeInfoArray[11];
        return info;
    } else {
        return nil;
    }
}

@end
